# #!/usr/bin/env python
# # -*- encoding: utf-8 -*-
# '''
# @File    :   APP_TransportLayer_test.py
# @Time    :   2025/03/20 13:31:28
# @Author  :   YangLiang 
# @Version :   1.0
# @Contact :   yangl@genvict.com
# @License :   (C)Copyright 2022-2025
# @Desc    :   UDS传输层协议测试
# '''

# import pytest
# import allure
# import time
# from pytest_assume.plugin import assume
# import Set_up
# from commDriver.TS_CAN import *

# uds_stuffing_byte = [0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA]

# class Test_UDS_TransportLayer:
    
#     @allure.severity('critical')
#     @allure.title('位填充规范验证测试')
#     @allure.description('''验证响应报文中的位填充字段：
#     1. 发送有效诊断请求
#     2. 检查响应报文填充字节是否为XX''')
#     def test_bit_stuffing_validation(self, action, Driver):
#         """
#         测试UDS传输层位填充功能的有效性
        
#         Args:
#             action: 测试动作对象
#             Driver: 包含CAN驱动的测试驱动对象
            
#         验证UDS响应中的位填充字节是否符合预期值0xaa
#         """
#         step = 1
#         step, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01 00 32 01 F4", 0, step, False)
#         time.sleep(1)
#         step, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, "03 22 F1 95", step)
#         # 计算所有数据的长度（UDS首帧格式：PCI高4位为0x1，低4位+第二个字节为总长度）
#         data_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#         # 计算总帧数：首帧已包含6字节数据，后续每帧最多7字节
#         import math
#         frame_count = 1 if data_length <= 6 else math.ceil((data_length - 6) / 7) + 1
#         # 计算总长度：数据长度 + 帧计数(每个帧1字节PCI) + 2字节首帧PCI
#         total_length = data_length + frame_count - 1 + 2
        
#         if uds_resp:
#             # 获取所有的填充位
#             stuffing_bytes = uds_resp[total_length:]
#             with assume: assert stuffing_bytes == uds_stuffing_byte[:len(stuffing_bytes)],logging.error(f"位填充异常,实际值：{stuffing_bytes.hex()}, 预期值：{uds_stuffing_byte[:len(stuffing_bytes)].hex()}")
#         else:
#             logging.error("未接收到响应报文")
#             assert False

#     @allure.severity('normal')
#     @allure.title('P2CAN_Server时间参数测试-默认会话')
#     def test_session_timing_Default(self, action, Driver):  # 修正拼写错误：Defalut -> Default
#         iStep = 1
#         # 切换至目标会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep, False)
#         # 单独发送请求
#         iStep, _, elapsed = Driver['CAN'].Send_And_Receive(Driver, "02 3E 00", iStep)
#         logging.info(f"默认会话响应时间：{elapsed:.2f}ms")
#         with assume: assert elapsed <= 25,  logging.error(f"默认会话响应超时：{elapsed:.2f}ms")

#     @allure.severity('normal')
#     @allure.title('P2CAN_Server时间参数测试-扩展会话')
#     def test_session_timing_Extended(self, action, Driver):
#         iStep = 1
#         # 切换至目标会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03', 0, iStep, False)
#         # 单独发送请求
#         iStep, _, elapsed = Driver['CAN'].Send_And_Receive(Driver, "02 3E 00", iStep)
#         logging.info(f"扩展会话响应时间：{elapsed:.2f}ms")
#         with assume: assert elapsed <= 25,  logging.error(f"扩展会话响应超时：{elapsed:.2f}ms")

#     @allure.severity('minor')
#     @allure.title('异常响应处理测试')
#     def test_error_response_handling(self, action, Driver):
#         iStep = 1
#         # 切换至目标会话
#         iStep, uds_resp, _ = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01", 0, iStep, False)
#         time.sleep(1)
#         iStep, uds_resp, elapsed = Driver['CAN'].Send_And_Receive(Driver, "02 10 FF", iStep)
#         logging.info(f"异常会话响应时间：{elapsed:.2f}ms")
#         # 双重验证
#         with assume: assert elapsed <= 25,  logging.error("错误响应超时")
#         with assume: assert uds_resp[1:4] == [0x7F, 0x10, 0x12],  logging.error("错误响应格式异常")

#     @allure.severity('critical')
#     @allure.title('多帧传输控制测试, 仅发送首帧')
#     def test_multi_frame_transmission_with_first_frame(self, action, Driver):
#         iStep = 1
        
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False, 'UDS')
#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')
        
#         # 步骤3：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式（假设收到单帧流控）
#         with assume: 
#             assert flow_ctrl[0] == 0x30  # 流控帧类型
#             assert flow_ctrl[1] == 0x00  # 块大小（无限制）
#             assert flow_ctrl[2] == 0x00  # STmin=0ms
#             assert flow_ctrl[3] == 0xAA  # 填充验证
        
#         # 验证无后续连续帧响应（等待500ms）
#         time.sleep(0.5)
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#         with assume: assert len(raw_frames) == 0

#     @allure.severity('critical')
#     @allure.title('多帧传输控制测试, 正常发送两帧连续帧')
#     def test_multi_frame_transmission_with_two_consecutive_frames(self, action, Driver):
#         iStep = 1
        
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False, 'UDS')
#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')


#         # 步骤4：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式（假设收到单帧流控）
#         with assume: 
#             assert flow_ctrl[0] == 0x30  # 流控帧类型
#             assert flow_ctrl[1] == 0x00  # 块大小（无限制）
#             assert flow_ctrl[2] == 0x00  # STmin=0ms
#             assert flow_ctrl[3] == 0xAA  # 填充验证
            
#         # 步骤5：发送部分连续帧（正确拆分数据）
#         # 将剩余数据按7字节分组
#         chunks = [consecutive_data[i:i+7] for i in range(0, len(consecutive_data), 7)]
        
#         # 只发送前两个连续帧
#         for seq, chunk in enumerate(chunks[:2], start=1):
#             # 构造连续帧PCI：0x20 + 序列号
#             cont_frame = [0x20 + seq] + chunk
#             # 填充剩余字节为0xAA
#             cont_frame += [0xAA] * (8 - len(cont_frame))
#             # 发送连续帧
#             Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)
        
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#         if len(raw_frames) > 0:
#             uds_resp = []
#             for frame in raw_frames:
#                 uds_resp.extend(frame['raw_data'])  # 合并所有原始数据

#             respstr = binascii.b2a_hex(bytearray(uds_resp), ' ')
#         with assume: assert len(raw_frames) == 0, logging.error(f"实际响应报文：{respstr}")

#     @allure.severity('critical')
#     @allure.title('多帧传输控制测试, 跳过第一个连续帧发送后续连续帧')
#     def test_multi_frame_transmission_skip_first_consecutive_frame(self, action, Driver):
#         iStep = 1
        
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False, 'UDS')
#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式（假设收到单帧流控）
#         with assume: 
#             assert flow_ctrl[0] == 0x30  # 流控帧类型
#             assert flow_ctrl[1] == 0x00  # 块大小（无限制）
#             assert flow_ctrl[2] == 0x00  # STmin=0ms
#             assert flow_ctrl[3] == 0xAA  # 填充验证
            
#         # 步骤5：发送部分连续帧（正确拆分数据）
#         # 将剩余数据按7字节分组
#         chunks = [consecutive_data[i:i+7] for i in range(0, len(consecutive_data), 7)]
        
#         # 跳过第一个连续帧,直接发送后续连续帧
#         for seq, chunk in enumerate(chunks[:], start=2):
#             # 构造连续帧PCI：0x20 + 序列号
#             cont_frame = [0x20 + seq] + chunk
#             # 填充剩余字节为0xAA
#             cont_frame += [0xAA] * (8 - len(cont_frame))
#             # 发送连续帧
#             Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)
        
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#         with assume: assert len(raw_frames) == 0

#     @allure.severity('critical')
#     @allure.title('多帧传输控制测试, 第一个连续帧发送两次,再发送后续连续帧')
#     def test_multi_frame_transmission_send_first_frame_twice(self, action, Driver):
#         iStep = 1
        
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False, 'UDS')
#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式（假设收到单帧流控）
#         with assume: 
#             assert flow_ctrl[0] == 0x30  # 流控帧类型
#             assert flow_ctrl[1] == 0x00  # 块大小（无限制）
#             assert flow_ctrl[2] == 0x00  # STmin=0ms
#             assert flow_ctrl[3] == 0xAA  # 填充验证
            
#         # 步骤5：发送部分连续帧（正确拆分数据）
#         # 将剩余数据按7字节分组
#         chunks = [consecutive_data[i:i+7] for i in range(0, len(consecutive_data), 7)]
        
#         # 发送两次第一个连续帧,再发送后续连续帧
#         for seq, chunk in enumerate(chunks[:], start=1):
#             # 构造连续帧PCI：0x20 + 序列号
#             cont_frame = [0x20 + seq] + chunk
#             # 填充剩余字节为0xAA
#             cont_frame += [0xAA] * (8 - len(cont_frame))
#             # 发送连续帧
#             if seq == 1:
#                 Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)
#             Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)
        
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#         if len(raw_frames) > 0:
#             uds_resp = []
#             for frame in raw_frames:
#                 uds_resp.extend(frame['raw_data'])  # 合并所有原始数据

#             respstr = binascii.b2a_hex(bytearray(uds_resp), ' ')

#         with assume: assert len(raw_frames) == 0, logging.error(f"实际响应报文：{respstr}")
        

#     @allure.severity('critical')
#     @allure.title('多帧传输控制测试, 延时N_Cr*1.1后发送连续帧')
#     def test_multi_frame_transmission_delayed_consecutive_frames(self, action, Driver):
#         iStep = 1
        
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False, 'UDS')
#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式（假设收到单帧流控）
#         with assume: 
#             assert flow_ctrl[0] == 0x30  # 流控帧类型
#             assert flow_ctrl[1] == 0x00  # 块大小（无限制）
#             assert flow_ctrl[2] == 0x00  # STmin=0ms
#             assert flow_ctrl[3] == 0xAA  # 填充验证

#         # 计算N_Cr
#         N_Cr = 150 * 1.1   # 转换为毫秒
#         logging.info(f"计算得到的N_Cr: {N_Cr}ms")
#         time.sleep(N_Cr/1000)  # 等待N_Cr时间
            
#         # 步骤5：发送连续帧（正确拆分数据）
#         # 将剩余数据按7字节分组
#         chunks = [consecutive_data[i:i+7] for i in range(0, len(consecutive_data), 7)]

#         for seq, chunk in enumerate(chunks[:], start=1):
#             # 构造连续帧PCI：0x20 + 序列号
#             cont_frame = [0x20 + seq] + chunk
#             # 填充剩余字节为0xAA
#             cont_frame += [0xAA] * (8 - len(cont_frame))
#             # 发送连续帧
#             Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)

#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#         with assume: assert len(raw_frames) == 0
    
 
#     @allure.severity('critical')
#     @allure.title('多帧响应流控缺失测试')
#     @allure.description('''验证未发送流控帧时DUT的响应行为：
#     1. 进入编程会话
#     2. 发送需要多帧响应的请求
#     3. 不发送流控帧验证DUT无响应''')
#     def test_missing_flow_control_response(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)

#         # 步骤3：发送需要多帧响应的请求（构造长请求）
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, "03 22 F1 95", iStep, 0)
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 1)
#         # 验证首帧响应
#         with assume: assert raw_frames[0] == 0x10, logging.error("未收到首帧响应")
        
#         # 步骤4：不发送流控帧,等待500ms
#         time.sleep(0.5)
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
        
#         # 验证无后续响应
#         with assume: assert len(raw_frames) == 0, logging.error("检测到非法响应帧")

#     @allure.severity('critical')
#     @allure.title('延时流控响应测试')
#     @allure.description('''验证延迟发送流控帧时DUT的响应行为：
#     1. 进入编程会话
#     2. 发送需要多帧响应的请求
#     3. 延迟N_BS+100ms发送流控帧
#     4. 验证响应完整性''')
#     def test_delayed_flow_control_response(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
#         # 步骤2：发送22 F1 86请求
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "22 F1 86", "62 F1 86 03", 0, iStep, False)
        
#         # 步骤3：发送需要多帧响应的请求
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, "03 22 F1 95", iStep)
        
#         # 验证首帧响应
#         with assume: 
#             assert uds_resp[0] == 0x10, logging.error("未收到首帧响应")
#             total_length = (uds_resp[0] & 0x0F) << 8 | uds_resp[1]
#             logging.info(f"多帧响应总长度：{total_length}字节")

#         # 步骤4：计算延时时间（N_BS=150ms + 100ms）
#         delay_time = (150 + 100) / 1000  # 转换为秒
#         logging.info(f"开始延时{delay_time}s发送流控帧")
#         time.sleep(delay_time)
        
#         # 发送流控帧（允许后续帧传输）
#         flow_ctrl = [0x30, 0x00, 0x00] + [0xAA]*5  # 流控帧数据
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
        
#         # 接收后续响应帧（等待3秒超时）
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
        
#        # 验证无后续响应
#         with assume: assert len(raw_frames) == 0, logging.error("检测到非法响应帧")

#     @allure.severity('critical')
#     @allure.title('延时流控响应测试')
#     @allure.description('''验证延迟发送流控帧时DUT的响应行为：
#     1. 进入扩展会话
#     2. 发送需要多帧响应的请求
#     3. 延迟N_BS+100ms发送两个不同STmin的流控帧
#     4. 验证按第一个流控帧参数响应''')
#     def test_delayed_flow_control_response(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
#         # 步骤2：发送22 F1 86请求
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "22 F1 86", "62 F1 86 03", 0, iStep, False)
        
#         # 步骤3：发送需要多帧响应的请求
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, "03 22 F1 95", iStep)
        
#         # 验证首帧响应
#         with assume: 
#             assert uds_resp[0] == 0x10, logging.error("未收到首帧响应")
#             total_length = (uds_resp[0] & 0x0F) << 8 | uds_resp[1]
#             logging.info(f"多帧响应总长度：{total_length}字节")
        
#         # 步骤4：发送两个不同参数的流控帧
#         logging.info("发送第一个流控帧(STmin=10ms)")
#         flow_ctrl_1 = [0x30, 0x00, 0x0A] + [0xAA]*5  # 块大小=0, STmin=0x0A(10ms)
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_1, Set_up.CAN_Type, True)
        
#         logging.info("发送第二个流控帧(STmin=50ms)")
#         flow_ctrl_2 = [0x30, 0x01, 0x32] + [0xAA]*5  # 块大小=1, STmin=0x32(50ms) 
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_2, Set_up.CAN_Type, True)
        
#         # 接收响应并记录时间戳
#         start_time = time.time()
#         raw_frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#         timestamps = [time.time()]  # 记录每帧到达时间
        
#         # 计算帧间隔是否符合第一个流控帧参数
#         if len(raw_frames) > 1:
#             for i in range(1, len(raw_frames)):
#                 interval = (timestamps[i] - timestamps[i-1])*1000  # 转换为毫秒
#                 with assume: 
#                     assert 8 <= interval <= 12, logging.error(f"帧间隔异常: 期望10ms±2ms,实际{interval:.2f}ms")

#     @allure.severity('critical')
#     @allure.title('多帧传输流控帧响应测试')
#     @allure.description('''验证DUT在N_Bs超时时间内响应流控帧：
#     1. 进入编程会话
#     2. 发送需要多帧传输的请求
#     3. 验证DUT在N_Bs时间内响应流控帧''')
#     def test_flow_control_response_within_NBs(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False)
#         # 步骤3：发送22 F1 86请求
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "22 F1 86", "62 F1 86 02", 0, iStep, False)
        
#         # 步骤4：发送需要多帧响应的请求
#         start_time = time.time()
#         # 步骤4：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         # 步骤4：发送首帧请求（构造超过7字节的长请求）
#         # 原始数据（包含服务ID 2E和参数）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
        
#         # 构造首帧（前2字节为PCI类型+长度）
#         total_length = len(payload)
#         first_frame = [0x10 | (total_length >> 8),  # PCI类型(1) + 长度高字节
#             total_length & 0xFF,          # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 构造连续帧数据（剩余16字节）
#         consecutive_data = payload[6:]
#         iStep, uds_resp, elapsed = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
#         logging.info(f"流控帧响应时间：{elapsed:.2f}ms")
  
#         # 验证首帧响应和流控帧响应时间
#         with assume:  assert elapsed <= 150, logging.error(f"流控帧响应超时: {elapsed:.2f}ms > 150ms(N_Bs)")
        
#         # 验证流控帧格式
#         with assume:
#             assert uds_resp[0] == 0x30  # 流控帧类型
#             assert uds_resp[1] == 0x00  # 块大小（无限制）
#             assert uds_resp[2] <= 0x00  # STmin<=50ms
    
#     @allure.severity('critical')
#     @allure.title('多帧响应连续帧接收测试')
#     @allure.description('''验证DUT在收到流控帧后能正确发送所有连续帧：
#     1. 发送需要多帧响应的请求
#     2. 发送BS=0的流控帧
#     3. 验证所有连续帧在N_Cr超时内被接收''')
#     def test_multi_frame_response_reception(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         start_time = time.time()
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, "03 22 F1 95", iStep)
        
#         # 验证首帧响应
#         with assume: 
#             assert uds_resp[0] == 0x10, logging.error("未收到首帧响应")
#             total_length = (uds_resp[0] & 0x0F) << 8 | uds_resp[1]
#             logging.info(f"多帧响应总长度：{total_length}字节")
        
#         # 步骤3：发送BS=0的流控帧
#         flow_ctrl = [0x30, 0x00, 0x00] + [0xAA]*5  # BS=0, STmin=0
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
        
#         # 接收所有连续帧并验证时间间隔
#         raw_frames = []
#         last_frame_time = time.time()
#         N_Cr = 150  # N_Cr超时时间(ms)
        
#         while True:
#             frames = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, N_Cr/1000)
#             if not frames:
#                 break
                
#             current_time = time.time()
#             interval = (current_time - last_frame_time) * 1000  # 转换为毫秒
#             with assume: 
#                 assert interval <= N_Cr, logging.error(f"连续帧接收超时: {interval:.2f}ms > {N_Cr}ms(N_Cr)")
#             last_frame_time = current_time
#             raw_frames.extend(frames)
        
#         # 验证接收到的帧数量是否符合预期
#         expected_frames = (total_length - 6 + 6) // 7  # 计算预期连续帧数量
#         with assume: 
#             assert len(raw_frames) >= expected_frames, logging.error(f"接收帧数量不足: 实际{len(raw_frames)}, 预期{expected_frames}")
        
#     @allure.severity('critical')
#     @allure.title('多帧响应STmin参数测试')
#     @allure.description('''验证不同STmin参数下DUT的连续帧响应：
#     1. 发送需要多帧响应的请求
#     2. 发送不同STmin值的流控帧
#     3. 验证连续帧间隔符合STmin参数''')
#     def test_multi_frame_response_with_various_stmin(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 测试不同的STmin值
#         stmin_values = [0x00, 0x64, 0xC8, 0xF3, 0xF5]  # 0ms, 100ms, 200ms, 243ms, 245ms
        
#         for stmin in stmin_values:
#             logging.info(f"开始测试STmin={hex(stmin)}")
            
#             # 步骤2：发送需要多帧响应的请求
#             start_time = time.time()
#             iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, "03 22 F1 95", iStep)
            
#             # 验证首帧响应
#             with assume: 
#                 assert uds_resp[0] == 0x10, logging.error("未收到首帧响应")
#                 total_length = (uds_resp[0] & 0x0F) << 8 | uds_resp[1]
#                 logging.info(f"多帧响应总长度：{total_length}字节")
            
#             # 步骤3：发送带指定STmin的流控帧
#             flow_ctrl = [0x30, 0x00, stmin] + [0xAA]*5  # BS=0, STmin=参数值
#             Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
            
#             # 接收所有连续帧并验证时间间隔
#             raw_frames = []
#             last_frame_time = time.time()
#             expected_interval = stmin if stmin <= 0xF0 else stmin - 0xF0  # 处理特殊STmin值
            
#             while True:
#                 frames = Driver['CAN'].recv_frame_by_id(Driver, Set_up.resID, 3)
#                 if not frames:
#                     break
                    
#                 current_time = time.time()
#                 interval = (current_time - last_frame_time) * 1000  # 转换为毫秒
                
#                 # 仅从第二帧开始验证间隔
#                 if len(raw_frames) > 0:
#                     with assume: 
#                         assert interval >= expected_interval - 2, logging.error(
#                             f"STmin={hex(stmin)}: 帧间隔{interval:.2f}ms < 预期{expected_interval}ms")
#                 last_frame_time = current_time
#                 raw_frames.extend(frames)
            
#             # 验证接收到的帧数量是否符合预期
#             expected_frames = (total_length - 6 + 6) // 7  # 计算预期连续帧数量
#             with assume: 
#                 assert len(raw_frames) >= expected_frames, logging.error(
#                     f"STmin={hex(stmin)}: 接收帧数量不足: 实际{len(raw_frames)}, 预期{expected_frames}")
            
#             # 等待1秒确保测试间隔
#             time.sleep(1)

#     @allure.severity('critical')
#     @allure.title('多帧请求流控帧响应测试(STmin=0)')
#     @allure.description('''验证DUT对多帧请求的流控帧响应：
#     1. 发送需要多帧传输的请求
#     2. 验证DUT响应流控帧且STmin=0''')
#     def test_flow_control_response_stmin_zero(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：构造多帧请求（22字节）
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
#         total_length = len(payload)
        
#         # 构造首帧
#         first_frame = [
#             0x10 | (total_length >> 8),  # PCI类型+长度高字节
#             total_length & 0xFF,         # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 步骤3：发送首帧并接收流控帧
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式（STmin=0）
#         with assume: 
#             assert flow_ctrl[0] == 0x30, logging.error("流控帧类型错误")
#             assert flow_ctrl[1] == 0x00, logging.error("块大小不为0")
#             assert flow_ctrl[2] == 0x00, logging.error("STmin不为0")
#             assert flow_ctrl[3] == 0xAA, logging.error("填充字节错误")

#     @allure.severity('normal')
#     @allure.title('单帧响应长度验证测试')
#     @allure.description('''验证DUT对单帧请求的响应长度：
#     1. 发送单帧请求
#     2. 验证响应帧长度符合预期''')
#     def test_single_frame_response_length(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入默认会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01", 0, iStep, False)
        
#         # 步骤2：发送单帧请求（读取DID F186）
#         request = "03 22 F1 86"
#         expected_length = 4  # 预期响应长度（62 F1 86 XX）
        
#         # 发送请求并接收响应
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证响应长度
#         with assume:
#             assert uds_resp[0] == expected_length, logging.error(
#                 f"响应长度错误: 实际{len(uds_resp)}字节, 预期{expected_length}字节")
#             assert uds_resp[1] == 0x62, logging.error("响应服务ID错误")
#             assert uds_resp[2] == 0xF1, logging.error("响应DID高字节错误")
#             assert uds_resp[3] == 0x86, logging.error("响应DID低字节错误")

#     @allure.severity('critical')
#     @allure.title('多帧响应FF_DL验证测试')
#     @allure.description('''验证DUT多帧响应的首帧FF_DL是否正确：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧FF_DL符合预期''')
#     def test_multi_frame_response_ffdl_validation(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A   # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             received_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert received_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{received_length}, 预期{expected_length}")
            
#         # 验证首帧数据部分
#         with assume:
#             assert uds_resp[2] == 0x62, logging.error("响应服务ID错误")
#             assert uds_resp[3] == 0xF1, logging.error("响应DID高字节错误") 
#             assert uds_resp[4] == 0x7E, logging.error("响应DID低字节错误")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中新请求干扰测试')
#     @allure.description('''验证DUT在多帧响应过程中对新单帧请求的处理：
#     1. 发送需要多帧响应的请求
#     2. 发送流控帧并接收第一个连续帧
#     3. 发送新的单帧请求
#     4. 验证DUT继续完成原多帧响应''')
#     def test_multi_frame_response_with_interruption(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             logging.info(f"多帧响应总长度：{total_length}字节")
        
#         # 步骤3：发送流控帧(BS=1, STmin=0)
#         flow_ctrl = [0x30, 0x01, 0x00] + [0xAA]*5
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：接收第一个连续帧
#         first_cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#         with assume:
#             assert len(first_cont_frame) > 0, logging.error("未收到第一个连续帧")
#             assert first_cont_frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
        
#         # 步骤5：发送新的单帧请求(03 22 F1 86)
#         interrupt_request = [0x03, 0x22, 0xF1, 0x86] + [0xAA]*4
#         Driver['CAN'].TransmitData(Set_up.reqID, interrupt_request, Set_up.CAN_Type, True)
        
#         # 步骤6：验证DUT继续发送后续连续帧
#         remaining_frames = []
#         expected_frames = (total_length - 6 + 6) // 7 - 1  # 减去已接收的第一个连续帧
        
#         for _ in range(expected_frames):
#             frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame) > 0, logging.error("未收到预期的连续帧")
#                 assert frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#                 # 验证填充字节
#                 assert all(b == 0xAA for b in frame[0]['raw_data'][7:]), logging.error("填充字节错误")
#             remaining_frames.append(frame)
        
#         # 验证总帧数
#         with assume:
#             assert len(remaining_frames) == expected_frames, logging.error(
#                 f"连续帧数量不足: 实际{len(remaining_frames)}, 预期{expected_frames}")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中新首帧请求干扰测试')
#     @allure.description('''验证DUT在多帧响应过程中对新首帧请求的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧FF_DL正确
#     3. 发送流控帧并接收第一个连续帧
#     4. 发送新的首帧请求
#     5. 验证DUT继续完成原多帧响应''')
#     def test_multi_frame_response_with_first_frame_interruption(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送流控帧(BS=1, STmin=0)
#         flow_ctrl = [0x30, 0x01, 0x00] + [0xAA]*5
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：接收第一个连续帧(应包含数据21 xx...)
#         first_cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#         with assume:
#             assert len(first_cont_frame) > 0, logging.error("未收到第一个连续帧")
#             assert first_cont_frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             assert first_cont_frame[0]['raw_data'][0] & 0x0F == 0x1, logging.error("连续帧序号错误")
        
#         # 步骤5：发送新的首帧请求(干扰请求)
#         interrupt_request = [0x10 | (0x10 >> 8), 0x10 & 0xFF] + [0xAA]*6  # 模拟首帧
#         Driver['CAN'].TransmitData(Set_up.reqID, interrupt_request, Set_up.CAN_Type, True)
        
#         # 步骤6：验证DUT继续发送后续连续帧
#         remaining_frames = []
#         expected_frames = (total_length - 6 + 6) // 7 - 1  # 减去已接收的第一个连续帧
        
#         for _ in range(expected_frames):
#             frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame) > 0, logging.error("未收到预期的连续帧")
#                 assert frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             remaining_frames.append(frame)
        
#         # 验证总帧数
#         with assume:
#             assert len(remaining_frames) == expected_frames, logging.error(
#                 f"连续帧数量不足: 实际{len(remaining_frames)}, 预期{expected_frames}")


#     @allure.severity('critical')
#     @allure.title('多帧响应过程中连续帧干扰测试')
#     @allure.description('''验证DUT在多帧响应过程中对额外连续帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送流控帧并接收第一个连续帧
#     4. 发送干扰连续帧
#     5. 验证DUT继续完成原多帧响应''')
#     def test_multi_frame_response_with_consecutive_frame_interruption(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送流控帧(BS=1, STmin=0)
#         flow_ctrl = [0x30, 0x01, 0x00] + [0xAA]*5
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：接收第一个连续帧
#         first_cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#         with assume:
#             assert len(first_cont_frame) > 0, logging.error("未收到第一个连续帧")
#             assert first_cont_frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             assert first_cont_frame[0]['raw_data'][0] & 0x0F == 0x1, logging.error("连续帧序号错误")
        
#         # 步骤5：发送干扰连续帧(序号=2)
#         interrupt_frame = [0x22] + [0xAA]*7  # 构造序号为2的连续帧
#         Driver['CAN'].TransmitData(Set_up.reqID, interrupt_frame, Set_up.CAN_Type, True)
        
#         # 步骤6：验证DUT继续发送后续连续帧
#         remaining_frames = []
#         expected_frames = (total_length - 6 + 6) // 7 - 1  # 减去已接收的第一个连续帧
        
#         for _ in range(expected_frames):
#             frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame) > 0, logging.error("未收到预期的连续帧")
#                 assert frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             remaining_frames.append(frame)
        
#         # 验证总帧数
#         with assume:
#             assert len(remaining_frames) == expected_frames, logging.error(
#                 f"连续帧数量不足: 实际{len(remaining_frames)}, 预期{expected_frames}")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中超载流控帧干扰测试')
#     @allure.description('''验证DUT在多帧响应过程中对超载流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送正常流控帧并接收第一个连续帧
#     4. 发送超载流控帧
#     5. 验证DUT继续按原流控参数响应''')
#     def test_multi_frame_response_with_overload_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送正常流控帧(BS=1, STmin=10ms)
#         flow_ctrl_normal = [0x30, 0x01, 0x0A] + [0xAA]*5  # BS=1, STmin=10ms
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_normal, Set_up.CAN_Type, True)
        
#         # 步骤4：接收第一个连续帧
#         first_cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#         with assume:
#             assert len(first_cont_frame) > 0, logging.error("未收到第一个连续帧")
#             assert first_cont_frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             assert first_cont_frame[0]['raw_data'][0] & 0x0F == 0x1, logging.error("连续帧序号错误")
        
#         # 步骤5：发送超载流控帧(0x31表示超载)
#         flow_ctrl_overload = [0x31, 0x00, 0x00] + [0xAA]*5  # 超载流控帧
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_overload, Set_up.CAN_Type, True)
        
#         # 步骤6：验证DUT继续按正常流控参数(BS=1, STmin=10ms)发送后续帧
#         remaining_frames = []
#         expected_frames = (total_length - 6 + 6) // 7 - 1  # 减去已接收的第一个连续帧
        
#         for _ in range(expected_frames):
#             frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame) > 0, logging.error("未收到预期的连续帧")
#                 assert frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             remaining_frames.append(frame)
        
#         # 验证总帧数
#         with assume:
#             assert len(remaining_frames) == expected_frames, logging.error(
#                 f"连续帧数量不足: 实际{len(remaining_frames)}, 预期{expected_frames}")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中未知报文干扰测试')
#     @allure.description('''验证DUT在多帧响应过程中对未知报文的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送流控帧并接收第一个连续帧
#     4. 发送未知报文
#     5. 验证DUT继续完成原多帧响应''')
#     def test_multi_frame_response_with_unknown_message(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送流控帧(BS=1, STmin=0)
#         flow_ctrl = [0x30, 0x01, 0x00] + [0xAA]*5
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：接收第一个连续帧
#         first_cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#         with assume:
#             assert len(first_cont_frame) > 0, logging.error("未收到第一个连续帧")
#             assert first_cont_frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             assert first_cont_frame[0]['raw_data'][0] & 0x0F == 0x1, logging.error("连续帧序号错误")
        
#         # 步骤5：发送未知报文(非UDS协议格式)
#         unknown_message = [0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22]  # 随机构造的未知报文
#         Driver['CAN'].TransmitData(Set_up.reqID, unknown_message, Set_up.CAN_Type, True)
        
#         # 步骤6：验证DUT继续发送后续连续帧
#         remaining_frames = []
#         expected_frames = (total_length - 6 + 6) // 7 - 1  # 减去已接收的第一个连续帧
        
#         for _ in range(expected_frames):
#             frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame) > 0, logging.error("未收到预期的连续帧")
#                 assert frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             remaining_frames.append(frame)
        
#         # 验证总帧数
#         with assume:
#             assert len(remaining_frames) == expected_frames, logging.error(
#                 f"连续帧数量不足: 实际{len(remaining_frames)}, 预期{expected_frames}")

#     @allure.severity('critical')
#     @allure.title('多帧传输过程中新单帧请求测试')
#     @allure.description('''验证DUT在多帧传输过程中对新单帧请求的处理：
#     1. 发送多帧请求的首帧
#     2. 接收DUT的流控帧响应
#     3. 发送新的单帧请求
#     4. 验证DUT正确响应新单帧请求''')
#     def test_new_single_frame_during_multi_frame_transfer(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)

#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：构造多帧请求首帧(22字节)
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
#         total_length = len(payload)
#         first_frame = [
#             0x10 | (total_length >> 8),  # PCI类型+长度高字节
#             total_length & 0xFF,         # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 步骤5：发送首帧并接收流控帧
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式
#         with assume: 
#             assert flow_ctrl[0] == 0x30, logging.error("流控帧类型错误")
#             assert flow_ctrl[1] == 0x00, logging.error("块大小不为0")
#             assert flow_ctrl[2] == 0x00, logging.error("STmin不为0")
        
#         # 步骤6：发送新的单帧请求(读取DID F186)
#         new_request = "03 22 F1 86"
#         iStep, new_response, _ = Driver['CAN'].Send_And_Receive(Driver, new_request, iStep)
        
#         # 验证新单帧响应
#         with assume:
#             assert new_response[0] == 0x04, logging.error("响应长度错误")
#             assert new_response[1] == 0x62, logging.error("响应服务ID错误")
#             assert new_response[2] == 0xF1, logging.error("DID高字节错误")
#             assert new_response[3] == 0x86, logging.error("DID低字节错误")

#     @allure.severity('critical')
#     @allure.title('多帧传输过程中新首帧请求测试')
#     @allure.description('''验证DUT在多帧传输过程中对新首帧请求的处理：
#     1. 发送多帧请求的首帧
#     2. 接收DUT的流控帧响应
#     3. 发送新的首帧请求
#     4. 验证DUT正确响应新首帧请求''')
#     def test_new_first_frame_during_multi_frame_transfer(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)

#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：构造多帧请求首帧(22字节)
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
#         total_length = len(payload)
#         first_frame = [
#             0x10 | (total_length >> 8),  # PCI类型+长度高字节
#             total_length & 0xFF,         # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 步骤5：发送首帧并接收流控帧
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式
#         with assume: 
#             assert flow_ctrl[0] == 0x30, logging.error("流控帧类型错误")
#             assert flow_ctrl[1] == 0x00, logging.error("块大小不为0")
#             assert flow_ctrl[2] == 0x00, logging.error("STmin不为0")
        
#         # 步骤6：发送新的首帧请求(读取DID F17E)
#         payload = [0x22, 0xD0, 0x01] + [0xD0, 0x02]  +  [0xD0, 0x03] + [0xD0, 0x04] + [0xD0, 0x05]# 总长度22字节
#         total_length = len(payload)
#         first_frame = [
#             0x10 | (total_length >> 8),  # PCI类型+长度高字节
#             total_length & 0xFF,         # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
#         iStep, new_response, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证新首帧响应
#         with assume: 
#             assert new_response[0] == 0x30, logging.error("流控帧类型错误")
#             assert new_response[1] == 0x00, logging.error("块大小不为0")
#             assert new_response[2] == 0x00, logging.error("STmin不为0")

#     @allure.severity('critical')
#     @allure.title('多帧传输过程中新流控帧干扰测试')
#     @allure.description('''验证DUT在多帧传输过程中对新流控帧的处理：
#     1. 发送多帧请求的首帧
#     2. 接收DUT的流控帧响应
#     3. 发送新的流控帧
#     4. 发送剩余的连续帧
#     5. 验证DUT正确完成原多帧响应''')
#     def test_new_flow_control_during_multi_frame_transfer(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)

#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：构造多帧请求首帧(22字节)
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
#         total_length = len(payload)
#         first_frame = [
#             0x10 | (total_length >> 8),  # PCI类型+长度高字节
#             total_length & 0xFF,         # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 步骤5：发送首帧并接收流控帧
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式
#         with assume: 
#             assert flow_ctrl[0] == 0x30, logging.error("流控帧类型错误")
#             assert flow_ctrl[1] == 0x00, logging.error("块大小不为0")
#             assert flow_ctrl[2] == 0x00, logging.error("STmin不为0")
        
#         # 步骤6：发送新的流控帧(修改参数)
#         new_flow_ctrl = [0x30, 0x01, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00]  # BS=1, STmin=10ms
#         Driver['CAN'].TransmitData(Set_up.reqID, new_flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤7：发送剩余的连续帧
#         remaining_payload = payload[6:]
#         for i in range(0, len(remaining_payload), 7):
#             chunk = remaining_payload[i:i+7]
#             cont_frame = [0x20 | ((i//7 + 1) & 0x0F)] + chunk  # 连续帧序号递增
#             cont_frame += [0xAA] * (8 - len(cont_frame))
#             Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)
        
#         # 步骤8：验证DUT响应
#         response = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 2)
#         with assume:
#             assert len(response) > 0, logging.error("未收到DUT响应")
#             assert response[0]['raw_data'][0] == 0x6E, logging.error("响应服务ID错误")
#             assert response[0]['raw_data'][1] == 0xF1, logging.error("DID高字节错误")
#             assert response[0]['raw_data'][2] == 0x06, logging.error("DID低字节错误")

#     @allure.severity('critical')
#     @allure.title('多帧传输过程中未知报文干扰测试')
#     @allure.description('''验证DUT在多帧传输过程中对未知报文的处理：
#     1. 发送多帧请求的首帧
#     2. 接收DUT的流控帧响应
#     3. 发送未知报文
#     4. 发送剩余的连续帧
#     5. 验证DUT正确完成原多帧响应''')
#     def test_unknown_message_during_multi_frame_transfer(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)

#         # 步骤2：进入编程会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02", 0, iStep, False, 'UDS')

        
        
#         # 步骤4：构造多帧请求首帧(22字节)
#         payload = [0x2E, 0xF1, 0x90] + list(range(0x01, 0x17))  # 总长度22字节
#         total_length = len(payload)
#         first_frame = [
#             0x10 | (total_length >> 8),  # PCI类型+长度高字节
#             total_length & 0xFF,         # 长度低字节
#         ] + payload[0:6]  # 首帧携带前6字节
        
#         # 步骤5：发送首帧并接收流控帧
#         iStep, flow_ctrl, _ = Driver['CAN'].Send_And_Receive(Driver, first_frame, iStep)
        
#         # 验证流控帧格式
#         with assume: 
#             assert flow_ctrl[0] == 0x30, logging.error("流控帧类型错误")
#             assert flow_ctrl[1] == 0x00, logging.error("块大小不为0")
#             assert flow_ctrl[2] == 0x00, logging.error("STmin不为0")
        
#         # 步骤6：发送未知报文(非ISO-TP格式)
#         unknown_message = [0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22]  # 随机构造的未知报文
#         Driver['CAN'].TransmitData(Set_up.reqID, unknown_message, Set_up.CAN_Type, True)
        
#         # 步骤7：发送剩余的连续帧
#         remaining_payload = payload[6:]
#         for i in range(0, len(remaining_payload), 7):
#             chunk = remaining_payload[i:i+7]
#             cont_frame = [0x20 | ((i//7 + 1) & 0x0F)] + chunk  # 连续帧序号递增
#             cont_frame += [0xAA] * (8 - len(cont_frame))  # 填充至8字节
#             Driver['CAN'].TransmitData(Set_up.reqID, cont_frame, Set_up.CAN_Type, True)
        
#         # 步骤8：验证DUT响应
#         response = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 2)
#         with assume:
#             assert len(response) > 0, logging.error("未收到DUT响应")
#             assert response[0]['raw_data'][0] == 0x6E, logging.error("响应服务ID错误")
#             assert response[0]['raw_data'][1] == 0xF1, logging.error("DID高字节错误")
#             assert response[0]['raw_data'][2] == 0x06, logging.error("DID低字节错误")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中过载流控帧测试')
#     @allure.description('''验证DUT在多帧响应过程中对过载流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送过载流控帧(0x31)
#     4. 验证DUT不发送后续连续帧''')
#     def test_multi_frame_response_with_overload_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x18    # 预期响应总长度(24字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送过载流控帧(0x31表示过载)
#         flow_ctrl_overload = [0x31, 0x00, 0x00] + [0xAA]*5  # 过载流控帧
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_overload, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT不发送连续帧
#         cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(cont_frame) == 0, logging.error("DUT在过载状态下不应发送连续帧")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中BS流控测试')
#     @allure.description('''验证DUT在多帧响应过程中对BS流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送BS=2的流控帧
#     4. 验证DUT按BS=2发送连续帧''')
#     def test_multi_frame_response_with_bs_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送BS=2的流控帧
#         flow_ctrl_bs2 = [0x30, 0x02, 0x00] + [0xAA]*5  # BS=2, STmin=0ms
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_bs2, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT按BS=2发送连续帧
#         received_blocks = 0
#         expected_blocks = (total_length - 6 + 6) // (7 * 2)  # 计算预期块数
        
#         for block in range(expected_blocks):
#             # 接收第一个连续帧(块内第一帧)
#             frame1 = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame1) > 0, logging.error(f"未收到块{block}的第一帧")
#                 assert frame1[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
            
#             # 接收第二个连续帧(块内第二帧)
#             frame2 = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame2) > 0, logging.error(f"未收到块{block}的第二帧")
#                 assert frame2[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
            
#             received_blocks += 1
        
#         # 验证总块数
#         with assume:
#             assert received_blocks == expected_blocks, logging.error(
#                 f"连续帧块数不足: 实际{received_blocks}, 预期{expected_blocks}")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中BS=0流控测试')
#     @allure.description('''验证DUT在多帧响应过程中对BS=0流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送BS=0的流控帧
#     4. 验证DUT持续发送所有剩余连续帧''')
#     def test_multi_frame_response_with_bs0_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送BS=0的流控帧
#         flow_ctrl_bs0 = [0x30, 0x00, 0x00] + [0xAA]*5  # BS=0, STmin=0ms
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_bs0, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT持续发送所有剩余连续帧
#         received_frames = 0
#         expected_frames = (total_length - 6 + 6) // 7  # 计算预期帧数
        
#         for _ in range(expected_frames):
#             frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 0.5)
#             with assume:
#                 assert len(frame) > 0, logging.error("未收到预期的连续帧")
#                 assert frame[0]['raw_data'][0] >> 4 == 0x2, logging.error("不是连续帧")
#             received_frames += 1
        
#         # 验证总帧数
#         with assume:
#             assert received_frames == expected_frames, logging.error(
#                 f"连续帧数量不足: 实际{received_frames}, 预期{expected_frames}")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中无效流控帧测试')
#     @allure.description('''验证DUT在多帧响应过程中对无效流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送无效流控帧(PCI类型错误)
#     4. 验证DUT不发送后续连续帧''')
#     def test_multi_frame_response_with_invalid_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送无效流控帧(PCI类型=0x40,非标准流控帧类型)
#         invalid_flow_ctrl = [0x40, 0x00, 0x00] + [0xAA]*5  # 无效流控帧
#         Driver['CAN'].TransmitData(Set_up.reqID, invalid_flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT不发送连续帧
#         cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(cont_frame) == 0, logging.error("DUT在收到无效流控帧后不应发送连续帧")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中等待状态流控测试')
#     @allure.description('''验证DUT在多帧响应过程中对等待状态流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送等待状态流控帧(0x32)
#     4. 验证DUT不发送后续连续帧''')
#     def test_multi_frame_response_with_wait_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送等待状态流控帧(0x32表示等待)
#         flow_ctrl_wait = [0x32, 0x00, 0x00] + [0xAA]*5  # 等待状态流控帧
#         Driver['CAN'].TransmitData(Set_up.reqID, flow_ctrl_wait, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT不发送连续帧
#         cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(cont_frame) == 0, logging.error("DUT在等待状态下不应发送连续帧")
        
#     @allure.severity('critical')
#     @allure.title('多帧响应过程中长度错误流控帧测试')
#     @allure.description('''验证DUT在多帧响应过程中对长度错误流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送长度不正确的流控帧(5字节)
#     4. 验证DUT不发送后续连续帧''')
#     def test_multi_frame_response_with_invalid_length_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送长度不正确的流控帧(5字节)
#         invalid_length_flow_ctrl = [0x30, 0x00, 0x00, 0xAA, 0xAA]  # 仅5字节
#         Driver['CAN'].TransmitData(Set_up.reqID, invalid_length_flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT不发送连续帧
#         cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(cont_frame) == 0, logging.error("DUT在收到长度错误流控帧后不应发送连续帧")

#     @allure.severity('critical')
#     @allure.title('多帧响应过程中功能寻址流控帧测试')
#     @allure.description('''验证DUT在多帧响应过程中对功能寻址流控帧的处理：
#     1. 发送需要多帧响应的请求
#     2. 验证首帧响应
#     3. 发送功能寻址流控帧
#     4. 验证DUT不发送后续连续帧''')
#     def test_multi_frame_response_with_functional_flow_control(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送需要多帧响应的请求
#         request = "03 22 F1 95"  # 读取DID F17E
#         expected_length = 0x1A    # 预期响应总长度(26字节)
        
#         iStep, uds_resp, _ = Driver['CAN'].Send_And_Receive(Driver, request, iStep)
        
#         # 验证首帧响应和FF_DL
#         with assume:
#             assert uds_resp[0] >> 4 == 0x1, logging.error("PCI类型错误,不是首帧")
#             total_length = ((uds_resp[0] & 0x0F) << 8) | uds_resp[1]
#             assert total_length == expected_length, logging.error(
#                 f"FF_DL长度错误: 实际{total_length}, 预期{expected_length}")
        
#         # 步骤3：发送功能寻址流控帧(使用功能寻址ID)
#         functional_flow_ctrl = [0x30, 0x00, 0x00] + [0xAA]*5  # 正常流控帧内容
#         Driver['CAN'].TransmitData(Set_up.AFctID, functional_flow_ctrl, Set_up.CAN_Type, True)
        
#         # 步骤4：验证DUT不发送连续帧
#         cont_frame = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(cont_frame) == 0, logging.error("DUT在收到功能寻址流控帧后不应发送连续帧")

#     @allure.severity('critical')
#     @allure.title('单帧请求长度错误测试')
#     @allure.description('''验证DUT对数据长度不正确的单帧请求的处理：
#     1. 进入扩展会话
#     2. 发送长度不正确的单帧请求
#     3. 验证DUT不响应''')
#     def test_invalid_length_single_frame_request(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送长度不正确的单帧请求(长度字段=0x04但实际数据长度=7)
#         invalid_single_frame = [0x08, 0x2E, 0xF1, 0x9D, 0xAA, 0xBB, 0xAA]  # 长度字段与实际不符
#         Driver['CAN'].TransmitData(Set_up.reqID, invalid_single_frame, Set_up.CAN_Type, True)
        
#         # 步骤3：验证DUT不响应
#         response = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(response) == 0, logging.error("DUT不应响应长度错误的单帧请求")


#     @allure.severity('critical')
#     @allure.title('单帧请求DLC错误测试')
#     @allure.description('''验证DUT对DLC不正确的单帧请求的处理：
#     1. 进入扩展会话
#     2. 发送DLC不正确的单帧请求
#     3. 验证DUT不响应''')
#     def test_invalid_dlc_single_frame_request(self, action, Driver):
#         iStep = 1
#         # 步骤1：进入扩展会话
#         iStep, _, _ = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03", 0, iStep, False)
        
#         # 步骤2：发送DLC不正确的单帧请求(实际DLC=4但发送8字节数据)
#         invalid_dlc_frame = [0x04, 0x2E, 0xF1, 0x9D, 0xAA, 0xBB, 0xCC, 0xDD]  # DLC=4但实际发送8字节
#         Driver['CAN'].TransmitData(Set_up.reqID, invalid_dlc_frame, Set_up.CAN_Type, True)
        
#         # 步骤3：验证DUT不响应
#         response = Driver['UDS'].recv_iso_tp_data(Set_up.resID, Set_up.CAN_Type, 1.0)
#         with assume:
#             assert len(response) == 0, logging.error("DUT不应响应DLC错误的单帧请求")

    